<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/pace-js@1/themes/blue/pace-theme-minimal.css">
  <script src="//cdn.jsdelivr.net/npm/pace-js@1/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yimig.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta property="og:type" content="article">
<meta property="og:title" content="【Part.2】IntelliJ IDEA小教程：代码操作篇">
<meta property="og:url" content="http://yimig.github.io/2018/10/01/tutorial_idea2/index.html">
<meta property="og:site_name" content="Tim&#39;s Blog">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_16-34-32.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_16-49-47.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-10-37.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-10-37-1.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/2018-10-01_17-11-40-300x195.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-18-48.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-20-02.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-22-56.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-27-51.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-22-26-298x300.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-49-48-300x209.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/chrome_2018-10-01_17-50-30.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-51-38-300x118.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-54-54-300x160.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_18-00-39-300x81.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_18-15-09-247x300.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/小时钟_2018-10-01_18-15-34-300x40.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/小时钟_2018-10-01_18-15-52.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-21-45-300x183.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-32-14-300x234.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-31-59-300x235.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-30-06-300x237.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-29-45-300x237.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-29-04-300x235.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-24-35-300x133.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-25-57.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-35-20-300x179.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-39-46-300x81.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-39-59-300x43.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-22-300x132.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-35-300x100.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-41-195x300.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-57-300x114.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-55-19-300x62.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-55-28.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-58-20.png">
<meta property="og:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_21-01-09.png">
<meta property="article:published_time" content="2018-10-01T13:02:49.000Z">
<meta property="article:modified_time" content="2020-10-28T15:38:55.657Z">
<meta property="article:author" content="Tim">
<meta property="article:tag" content="IntelliJ IDEA">
<meta property="article:tag" content="教程">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_16-34-32.png">

<link rel="canonical" href="http://yimig.github.io/2018/10/01/tutorial_idea2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>【Part.2】IntelliJ IDEA小教程：代码操作篇 | Tim's Blog</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64126ab668fa908027cba9464a0afec7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-math@4.0.0/dist/style.css">
<!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Tim's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Learn Everything!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/schedule/" rel="section"><i class="fa fa-fw fa-calendar"></i>日程表</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/yimig" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yimig.github.io/2018/10/01/tutorial_idea2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/uploads/avatar.png">
      <meta itemprop="name" content="Tim">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Tim's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          【Part.2】IntelliJ IDEA小教程：代码操作篇
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-10-01 21:02:49" itemprop="dateCreated datePublished" datetime="2018-10-01T21:02:49+08:00">2018-10-01</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-10-28 23:38:55" itemprop="dateModified" datetime="2020-10-28T23:38:55+08:00">2020-10-28</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Tutorial/" itemprop="url" rel="index"><span itemprop="name">Tutorial</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
              <span>2.7k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <hr>
<a id="more"></a>
<h1 id="①列操作"><a href="#①列操作" class="headerlink" title="①列操作"></a>①列操作</h1><p>假如我们想要将左图修改为右图的枚举形式，该如何快速操作呢？ <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_16-34-32"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_16-34-32.png" alt=""></a><a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_16-49-47"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_16-49-47.png" alt=""></a> 首先，说明一下<strong>选中文本</strong>的规则： 我们都知道当按下←/→时可以移动光标，如果我们想在移动时<strong>选中</strong>多个文本，就可以按下<strong>Shift+←</strong>或<strong>Shift+→</strong>，这样编译器就会选择光标移动范围的文本。 如果我们想将光标移动<strong>跳过一个词</strong>（单词、中文词等）时，可以按下<strong>Ctrl+←</strong>或<strong>Ctrl+→</strong>。另外，如果我们想让光标跳至行首，可以按下<strong>HOME</strong>键，如果我们想让光标跳至行尾，可以按下<strong>END</strong>键。 综上所述，我们可以拓展一下思维，如果我们想选中一个词，光标又在该词之前，我们就可以按下<strong>Ctrl+Shift+→</strong>来选中该词，如果我们想选中一行，光标又在一行的行尾，我们就可以按下Shift+HOME来选中这一行。 注意，这个规则是<strong>普适于所有文本编辑工具的</strong>，不仅限于IntelliJ IDEA。 那么我们继续IntelliJ IDEA教程： 通过对比两图我们不难发现前后的变化为： ①单词全部大写了，并且移动到了数字之前 ②数字添加了括号，除了最后一行结尾为分号外，每行结尾为逗号 ③文本被预格式化了，排版更加整洁 然后我们一一解决上面的问题： 首先我们将单词选中（Ctrl+Shift+→） <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-10-37"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-10-37.png" alt=""></a> 然后使用使用Toggle case<strong>大小写转换（Ctrl+Shift+U）</strong> <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-10-37-2"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-10-37-1.png" alt=""></a>，其对应Edit选项卡中的Toggle case： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/2018-10-01_17-11-40"><img src="http://47.94.231.166/wp-content/uploads/2018/10/2018-10-01_17-11-40-300x195.png" alt=""></a> 然后将其剪切（Ctrl+X），将光标移到行首（HOME），粘贴到行首（Ctrl+V），并手动为数字添加括号，注意数字也可以看为一个单词，所以按下Ctrl+→即可跳过一个数字 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-18-48"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-18-48.png" alt=""></a> 之后将光标跳到最后（END）删除多余的部分，添加逗号，这样一行就编辑完了。 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-20-02"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-20-02.png" alt=""></a> 然后我们介绍一下<strong>多列批量操作</strong>： 我们发现需要操作的每行都有个冒号作为分割点，这是个很好的提示信息，代表了我们需要更改文本的特性，可以与<strong>下面其他代码</strong>相分别的地方。将其选中。 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-22-56"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-22-56.png" alt=""></a> 然后按下<strong>Ctrl+Alt+Shift+J</strong>，即可选中所有冒号，这是我们惊喜地发现：光标分身了！ <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-27-51"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-27-51.png" alt=""></a> 这样，我们就可以做到列批量操作了，再重复上面的工作即可。 这个功能在Edit&gt;Find&gt;Select All Occurrence： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-22-26"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-22-26-298x300.png" alt=""></a> 如果我们需要批量更改的文本下面还有带冒号的代码怎么办？使用Ctrl+Alt+Shift+J不就一次都选中了？面对这种情况我们可以使用<strong>Alt+J</strong>，这样光标可以一次只“分身”一个，不会一次全部选中。</p>
<h1 id="②Live-Templates"><a href="#②Live-Templates" class="headerlink" title="②Live Templates"></a>②Live Templates</h1><p>Live Templates是一个<strong>模板定义工具</strong>，利用它定义模板即可快速输入代码，大大增加开发效率。 下面演示添加一个Main方法的模板： 按下Ctrl+Shift+A打开搜索工具，搜索Live Templates，打开即可得到以下窗口 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-49-48"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-49-48-300x209.png" alt=""></a> 点击右侧的“+”，选择<strong>“Template Group”</strong>，为我们的模板新定义一个分组存储 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/chrome_2018-10-01_17-50-30"><img src="http://47.94.231.166/wp-content/uploads/2018/10/chrome_2018-10-01_17-50-30.png" alt=""></a> 这里我们定义一个名为“常用方法”的分组： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-51-38"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-51-38-300x118.png" alt=""></a> 再点击右侧的“+”，这次选择<strong>“Live Template”</strong>为分组添加一个模板 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_17-54-54"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_17-54-54-300x160.png" alt=""></a> 在Abbreviation（缩写）中填入将模板唤起的文本，这里我们写入“main”，在Description（描述）中输入模板的描述，这是在我们输入缩写文字时提示的内容，这里我们写入“public static void main(String[] args)” <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_18-00-39"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_18-00-39-300x81.png" alt=""></a> 然后直接在Template text内输入函数体即可，注意这里有几种表达式(大小写随意，记得加美元$符号框起来就行）： ①<strong>\$VARx\$</strong>：x代表一个大于零的整数，<strong>表示这里将会有一个值</strong>，生成模板后会自动<strong>把光标移到这里</strong>，开发人员输入一个值后按下<strong>Enter</strong>即可跳到下一个值 ②<strong>\$END\$</strong>：表示这里将会有一个代码块，如函数体，生成模板后会自动<strong>把光标移到这里（如果有$VARx$先移动到$VARx$）</strong>，开发人员在这里可以自由换行，按下Enter也不会有跳转，所以如果后面有<strong>$VARx$</strong>编译器也不会引导开发人员，可以认为<strong>模板引导止步于此</strong> 跟据我们的需要，我们在这里填入</p>
<p>public static void main(String[] args)<br>{<br>  $END$<br>}</p>
<p>最后，在输入框下单击Define，为该模板定义一种适用类型，这里我们选择JAVA： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_18-15-09"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_18-15-09-247x300.png" alt=""></a> 至此模板已经定义完成，回到代码页面输入“main”就出现了我们定义的内容： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/%e5%b0%8f%e6%97%b6%e9%92%9f_2018-10-01_18-15-34"><img src="http://47.94.231.166/wp-content/uploads/2018/10/小时钟_2018-10-01_18-15-34-300x40.png" alt=""></a> 再按下<strong>Enter</strong>即可调用模板： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/%e5%b0%8f%e6%97%b6%e9%92%9f_2018-10-01_18-15-52"><img src="http://47.94.231.166/wp-content/uploads/2018/10/小时钟_2018-10-01_18-15-52.png" alt=""></a></p>
<h1 id="④postfix"><a href="#④postfix" class="headerlink" title="④postfix"></a>④postfix</h1><p>postfix也是一种Live Templates模板，不过这种模板由编译器设定，是归类了几种最常用的操作的模板集合。它比自定义的Live Templates更灵活方便。</p>
<h2 id="开启"><a href="#开启" class="headerlink" title="开启"></a>开启</h2><p>postfix默认状态下是开启的，如果不下心关闭，我们可以手动打开：按下Ctrl+Shift+A打开搜索器，输入postfix，打开相关设置界面，勾选“Enable postfix Conpletion”。 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_19-21-45"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-21-45-300x183.png" alt=""></a></p>
<h2 id="常用模板"><a href="#常用模板" class="headerlink" title="常用模板"></a>常用模板</h2><h3 id="①fori"><a href="#①fori" class="headerlink" title="①fori"></a>①fori</h3><p><a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_19-32-14"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-32-14-300x234.png" alt=""></a></p>
<h3 id="②return"><a href="#②return" class="headerlink" title="②return"></a>②return</h3><p><a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_19-31-59"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-31-59-300x235.png" alt=""></a></p>
<h3 id="③field"><a href="#③field" class="headerlink" title="③field"></a>③field</h3><p><a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_19-30-06"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-30-06-300x237.png" alt=""></a></p>
<h3 id="④sout"><a href="#④sout" class="headerlink" title="④sout"></a>④sout</h3><p><a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_19-29-45"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-29-45-300x237.png" alt=""></a></p>
<h3 id="⑤nn"><a href="#⑤nn" class="headerlink" title="⑤nn"></a>⑤nn</h3><p><a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_19-29-04"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_19-29-04-300x235.png" alt=""></a> 除了这些还有很多模板，可以自己学习一下找到最适合自己的。</p>
<h1 id="⑤Alt-Enter"><a href="#⑤Alt-Enter" class="headerlink" title="⑤Alt + Enter"></a>⑤Alt + Enter</h1><p>Alt+Enter快捷键实际上对应的是一个叫“Show Intent”的工具，类似于IntelliJ IDEA的一个小助手，它可以完成很多实用小功能。</p>
<h2 id="1-自动创建函数"><a href="#1-自动创建函数" class="headerlink" title="1.自动创建函数"></a>1.自动创建函数</h2><p>如果我们调用了一个赞为创建的方法，如下图的uuu()，编译器当然会报错，但是如果我们按下Alt+Enter，就会提示创建一个名为uuu的函数： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-24-35"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-24-35-300x133.png" alt=""></a> 再次按下Enter即可创建该函数： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-25-57"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-25-57.png" alt=""></a> 另外，如果在暂未定义的函数中传入变量，该工具还可以为新创建的函数填写形参，参数名即为传入的参数名。</p>
<h2 id="2-优化函数"><a href="#2-优化函数" class="headerlink" title="2.优化函数"></a>2.优化函数</h2><p>当使用for循环与使用foreach等效时，可使用Alt+Enter进行优化替换，与此相同的还有for、while互换等。 <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-35-20"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-35-20-300x179.png" alt=""></a></p>
<h2 id="3-字符串format"><a href="#3-字符串format" class="headerlink" title="3.字符串format"></a>3.字符串format</h2><p>将断开的字符串写法改成整体的字符串写法： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-39-46"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-39-46-300x81.png" alt=""></a> 效果： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-39-59"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-39-59-300x43.png" alt=""></a> 这种方式更方便我们的读写。</p>
<h2 id="4-实现接口"><a href="#4-实现接口" class="headerlink" title="4.实现接口"></a>4.实现接口</h2><p>我们定义接口后可以使用Alt+Enter自动创建一个承接该接口的类文件： 比如我们创建了test接口，里面有个test函数，我们对接口名使用Alt+Enter，选择”Implement interface” <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-47-22"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-22-300x132.png" alt=""></a> 选择创建的类名以及所在的包（package）： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-47-35"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-35-300x100.png" alt=""></a> 确认重写的函数： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-47-41"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-41-195x300.png" alt=""></a> 然后就完成了： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-47-57"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-47-57-300x114.png" alt=""></a></p>
<h2 id="5-英语纠错"><a href="#5-英语纠错" class="headerlink" title="5.英语纠错"></a>5.英语纠错</h2><p>当我们的拼写出错时，编译器会在出错的词下添加绿色波浪线，在这上面使用Alt+Enter，选择”Typo：Change to…” <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-55-19"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-55-19-300x62.png" alt=""></a> 即可出现建议的词语列表： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-55-28"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-55-28.png" alt=""></a> 选择正确的词语即可。</p>
<h2 id="6-导包"><a href="#6-导包" class="headerlink" title="6.导包"></a>6.导包</h2><p>当我们使用了未导入的库的函数、类时，编译器就会报错。如图中的List： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_20-58-20"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_20-58-20.png" alt=""></a> 这时我们按下Alt+Enter，IntelliJ IDEA就可以自动导入库： <a target="_blank" rel="noopener" href="http://upane.cn/archives/744/idea64_2018-10-01_21-01-09"><img src="http://47.94.231.166/wp-content/uploads/2018/10/idea64_2018-10-01_21-01-09.png" alt=""></a> 综上所述，当我们在编程时遇到问题就可以尽情使用Alt+Enter的提示去修复了。</p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/IntelliJ-IDEA/" rel="tag"># IntelliJ IDEA</a>
              <a href="/tags/%E6%95%99%E7%A8%8B/" rel="tag"># 教程</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/10/01/tutorial_install_emacsideas/" rel="prev" title="【教程】emacsIDEAs安装教程">
      <i class="fa fa-chevron-left"></i> 【教程】emacsIDEAs安装教程
    </a></div>
      <div class="post-nav-item">
    <a href="/2018/10/07/csharp_wpf_controler/" rel="next" title="【C#】WPF基础：基本控件篇">
      【C#】WPF基础：基本控件篇 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E2%91%A0%E5%88%97%E6%93%8D%E4%BD%9C"><span class="nav-number">1.</span> <span class="nav-text">①列操作</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E2%91%A1Live-Templates"><span class="nav-number">2.</span> <span class="nav-text">②Live Templates</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E2%91%A3postfix"><span class="nav-number">3.</span> <span class="nav-text">④postfix</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BC%80%E5%90%AF"><span class="nav-number">3.1.</span> <span class="nav-text">开启</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E6%A8%A1%E6%9D%BF"><span class="nav-number">3.2.</span> <span class="nav-text">常用模板</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E2%91%A0fori"><span class="nav-number">3.2.1.</span> <span class="nav-text">①fori</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E2%91%A1return"><span class="nav-number">3.2.2.</span> <span class="nav-text">②return</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E2%91%A2field"><span class="nav-number">3.2.3.</span> <span class="nav-text">③field</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E2%91%A3sout"><span class="nav-number">3.2.4.</span> <span class="nav-text">④sout</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E2%91%A4nn"><span class="nav-number">3.2.5.</span> <span class="nav-text">⑤nn</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E2%91%A4Alt-Enter"><span class="nav-number">4.</span> <span class="nav-text">⑤Alt + Enter</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%87%AA%E5%8A%A8%E5%88%9B%E5%BB%BA%E5%87%BD%E6%95%B0"><span class="nav-number">4.1.</span> <span class="nav-text">1.自动创建函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BC%98%E5%8C%96%E5%87%BD%E6%95%B0"><span class="nav-number">4.2.</span> <span class="nav-text">2.优化函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%AD%97%E7%AC%A6%E4%B8%B2format"><span class="nav-number">4.3.</span> <span class="nav-text">3.字符串format</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%AE%9E%E7%8E%B0%E6%8E%A5%E5%8F%A3"><span class="nav-number">4.4.</span> <span class="nav-text">4.实现接口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E8%8B%B1%E8%AF%AD%E7%BA%A0%E9%94%99"><span class="nav-number">4.5.</span> <span class="nav-text">5.英语纠错</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E5%AF%BC%E5%8C%85"><span class="nav-number">4.6.</span> <span class="nav-text">6.导包</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Tim"
      src="/uploads/avatar.png">
  <p class="site-author-name" itemprop="name">Tim</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">90</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">40</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yimig" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yimig" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:zhangyiming@programmer.net" title="E-Mail → mailto:zhangyiming@programmer.net" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://leetcode.com/yimig/" title="LeeCode → https:&#x2F;&#x2F;leetcode.com&#x2F;yimig&#x2F;" rel="noopener" target="_blank"><i class="fa fa-fw fa-code"></i>LeeCode</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.zhihu.com/people/tim-2-96" title="zhihu → https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;tim-2-96" rel="noopener" target="_blank"><i class="fa fa-fw fa-question-circle"></i>zhihu</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://upane.cn/" title="https:&#x2F;&#x2F;upane.cn" rel="noopener" target="_blank">博客旧址</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tim</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">183k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:46</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/three.min.js"></script>
    <script defer src="//cdn.jsdelivr.net/gh/theme-next/theme-next-three@1/canvas_sphere.min.js"></script>


  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/js/local-search.js"></script>













  

  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID    : 'a876807f33858291f9d9',
      clientSecret: '7a5c6a83611c309965d7339d7ca5f16e34a21e9f',
      repo        : 'yimig.github.io',
      owner       : 'yimig',
      admin       : ['yimig'],
      id          : 'd91b7dee00c8658c4750a6e8b8bf5747',
        language: '',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

</body>
</html>
